package ar.edu.itba.it.cg.grupo01.impl.color;

import java.awt.Color;

import javax.vecmath.Point3d;

import ar.edu.itba.it.cg.grupo01.impl.Camera;

public class LogVariation extends AbstractVariation {

	@Override
	protected Color apply(final Color shapeColor, final Camera camera, final Point3d closest) {
		final float[] hsb = Color.RGBtoHSB(shapeColor.getRed(),
				shapeColor.getGreen(), shapeColor.getBlue(), null);
		final float hue = hsb[0]; // .58333
		final float saturation = hsb[1]; // .66667
		float brightness = hsb[2]; // .6

		float far=20;
		
		final double distance = camera.getOrigin().distance(closest);
		final float deltaB =  (float) (Math.abs( (float) Math.log(((far-distance)))- ((Math.log(far)))));

		brightness=(float) (0.1+deltaB);
		

		if (brightness < 0.0f) {
			brightness = 0.0f;
		}

		// Convert HSB to RGB value
		final Color newColor = new Color(Color.HSBtoRGB(hue, saturation, brightness));

		return newColor;
	}

}
